package com.my.cd.factory.simpleFactory;

import com.my.cd.factory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 简单工厂的使用类：披萨订单类
 */
public class OrderPizza {

    SimplePizzaFactory simpleFactory;

    public OrderPizza(SimplePizzaFactory simpleFactory) {

        setFactory(simpleFactory);
    }

    public void setFactory(SimplePizzaFactory mSimplePizzaFactory) {
        Pizza pizza;
        String ordertype;
        this.simpleFactory = mSimplePizzaFactory;
        do {
            ordertype = gettype();
            pizza = mSimplePizzaFactory.CreatePizza(ordertype);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }
        } while (true);

    }

    private String gettype() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            return strin.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

}
